<template>
	<view class="main">
		<h2>修改密码</h2>
		<view class="msg">修改密码后,需要重新登录</view>
		<view class="input">
			<u--input v-model="oldpassword" placeholder="请输入旧密码" border="bottom" password></u--input>
			<u--input v-model="newpassword" placeholder="请输入新密码" border="bottom" password></u--input>
			<u--input v-model="confirmNew" placeholder="请确认新密码" border="bottom" password></u--input>
		</view>
		<view class="btn">
			<view class="in" @tap="confirm">
				确认修改
			</view>
		</view>
	</view>
</template>

<script>
	import {
		changepwd
	} from '@/api/user.js'
export default {
	data() {
		return {
			oldpassword:'',
			newpassword:'',
			confirmNew:''
		};
	},
	onLoad() {},
	methods: {
		async confirm() {
			if(this.oldpassword){
				uni.showToast({
					title:'请输入旧密码',
					icon:'none'
				})
				return
			}else if(this.newpassword){
				uni.showToast({
					title:'请输入新密码',
					icon:'none'
				})
				return
			}else if(this.newpassword != this.confirmNew){
				uni.showToast({
					title:'两次密码输入不一致',
					icon:'none'
				})
				return
			}else if(this.newpassword.length < 6){
				uni.showToast({
					title:'新密码最少为六位数',
					icon:'none'
				})
				return
			}else{
				let res = await changepwd({
					oldpassword: this.oldpassword,
					newpassword: this.newpassword
				})
				if(res.code == 1){
					uni.showToast({
						title:'修改成功',
						icon:'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url:'/pages/login/login'
						})
					},1000)
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.main {
	padding: 30px 15px 0;
	h2 {
		font-size: 26px;
		color: #232323;
		font-weight: 700;
		margin-bottom: 15px;
	}
	.msg {
		font-size: 14px;
		color: #9b9ca1;
		margin-bottom: 20px;
	}
	.input {
		margin-bottom: 20px;
		/deep/.u-input {
			margin-bottom: 10px;
		}
	}
	.btn{
		width: 100%;
		padding: 0 50px;
		.in{
			width: 100%;
			padding: 16px;
			text-align: center;
			color: #fff;
			background-color: #0C80FB;
			border-radius: 100px;
		}
	}
}
</style>
